package com.wsz.security.contorller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wsz.security.pojo.User;
import com.wsz.security.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private UserService userService;

    @GetMapping("/hello")
    public String get() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println("身份信息"+authentication.getPrincipal());
        //authentication.getCredentials()//认证成功会去掉 凭证信息
        System.out.println("权限信息"+authentication.getAuthorities());
        System.out.println(authentication.getName());

        return "hello world" + authentication.toString();
    }

    @GetMapping("/index")
    public String index(){
        String s = "root";
        User user = userService.getOne(new QueryWrapper<User>().eq("username",s));
        return user.getPassword();
    }


    @GetMapping("/fail")
    public String fail(){
        return "fail";
    }
}
